package entity

import (
	"save-kindle/source/ddd/definition"
	"save-kindle/source/ddd/dp"
)

type Book struct {
	dp.BookSource
	BookParser definition.Parser
	catalog    *Catalog
}

func NewBook(bookSource dp.BookSource, parser definition.Parser) Book {
	return Book{
		BookSource: bookSource,
		BookParser: parser,
	}
}

func (b *Book) GetCatalog(catalogUrl string) *Catalog {
	if b.catalog == nil {
		catalog := newCatalog(dp.BookCatalog{
			CatalogUrl: catalogUrl,
		}, b.BookParser)
		b.catalog = catalog
	}
	return b.catalog
}

func (b *Book) GetChapterList(catalogUrl string, parser definition.Parser) []*Chapter {
	return b.GetCatalog(catalogUrl).
		getChapterList(parser)
}
